<template>
      <div class="home">
          <el-container class="container">
            <el-header class="header">
                <div>
                    <img src="../assets/img/呵呵.jpg" alt="logo" width="60px" height="60px">
                    <span>AZAPP管理后台</span>
                </div>
                <el-button type="info" @click="logout">退出</el-button>
            </el-header>
            <el-container>
                <!-- 左侧菜单 -->
                <el-aside class="aside" :width="isCollapse ? '64px' : '200px'">
                    <div class="toggle-button" @click="toggleCollapse">|||</div>
                    <!-- 菜单栏组件 -->
                    <el-menu background-color="black" text-color="#fff"
                        active-text-color="#ffd04b" :unique-opened="true" 
                        :collapse="isCollapse" :collapse-transition="false" :router="true">
                        <!-- 一级菜单 -->
                        <el-submenu :index="item.menuid" v-for="item in menulist" :key="item.menuid">
                            <!-- 一级菜单的模板区域 -->
                            <template slot="title">
                                <!-- 图标 -->
                                <i :class="item.iconpath"></i>
                                <!-- 文本 -->
                                <span>{{ item.content }}</span>
                            </template>

                            <!-- 二级菜单 -->
                            <el-menu-item  v-for="subitem in item.children" :key="subitem.menuid" :index="'/'+subitem.path">
                                <template slot="title">
                                    <!-- 图标 -->
                                    <i :class="subitem.iconpath"></i>
                                    <!-- 文本 -->
                                    <span>{{ subitem.content }}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>

                    </el-menu>
                </el-aside>
                <!-- 主体区域 -->
                <el-main>
                    <!-- 路由占位符 -->
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
      </div>
</template>

<script>
export default {

    data(){
        return {
            //左侧菜单数据 
            menulist:[],
            isCollapse:false,
            example:{
                data:{
                    id:123,
                    content:'管理员设置',
                    iconpath:'xxxxx',
                    children:[
                        {
                            id:456,
                            content:'管理员列表',
                            iconpath:'aaaaa'
                        },
                        {
                            id:789,
                            content:'新增管理员',
                            iconpath:'bbbbb'
                        }
                    ]
                }
            }

        }
    },
    created(){
        //获取本页面的数据
        this.getMenuList()
    },
    methods:{
        logout(){
            window.sessionStorage.clear()
            this.$router.push('/login')
        },
        toggleCollapse(){
            this.isCollapse=!this.isCollapse
        },
        async getMenuList(){
            //获取所有的菜单
            const { data:res }=await this.$http.get('/admin/getMenus',{headers:{'token':window.sessionStorage.getItem('token')}})
            
            this.menulist=res.data;
            console.log(res)
        }
        // axios.get(url,{
        //     headers:{
        //         'token':'123123'
        //     },
        //     params:{
        //         name:'zhangsan',
        //         age:'20'
        //     }
        // })
    }
   

}
</script>

<style lang="less" scoped>
.home{
    height: 100%;
}
.container{
    height: 100%;
}
.header{
    color: white;
    background-color: black;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    font-size: 20px;
    > div{
        display: flex;
        align-items: center;
        span {
            margin-left: 15px;
        }
    }
}
.aside{
    color: white;
    background-color: black;
    height: 100%;
    .el-menu{
        border-right: none;
    }
}
.toggle-button{
    background-color: black;
    font-size: 10px;
    line-height: 24px;
    color: white;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
}

</style>>




